<template>
  <div class="unused-detail">
    <head-top head-title='商品详情' go-back="true"></head-top>
    <avatar :list="list"></avatar>
    <section class="desc">
      <div class="desc-wrapper">
        <div class="title">
          <div class="biaoti">
            <span class="name">{{list.title}}</span>
          </div>
          <div class="telphone" v-if="list.phone">
            <a :href="'tel:'+list.phone" class="tel">
              <span class="phone-image"></span>{{list.phone}}</a>
          </div>
          <div class="telphone" v-else></div>
        </div>
        <div class="because">
          <p v-html="list.content"></p>
        </div>
        <div class="price">
          <span class="new-price">￥{{list.money}}</span>
          <span class="read_num">阅读量：{{list.reading_amount}}</span>
        </div>
      </div>
    </section>
    <div class="split"></div>
    <section class="good-detail">
      <h3 class="title">商品详情</h3>
      <ul>
        <!--微信浏览器-->
        <li v-if="weixinShow" v-for="(item,index) in list.img">
          <div class="imgs" :style="'backgroundImage:url('+item+')'" @click="preview(index)"></div>
        </li>
        <!--普通浏览器图片展示-->
        <div v-if="ordinaryShow" class="img_pres">
          <div class="img-box" v-for="(url, index) in list.img" :style="{'background-image': 'url(' + url + ')'}"
               :key="index">
            <img preview="1" preview-text="" :src="url" alt="">
          </div>
        </div>
      </ul>
    </section>
    <div class="split"></div>
    <comment :list="list" :lists="lists" @passMethods="_getDetail"></comment>
  </div>
</template>

<script>
  import headTop from '../header/Header.vue'
  import avatar from '../common/avatar.vue'
  import comment from '../common/comment.vue'
  import { getDetail } from '../../api/publishList.js'
  import wx from 'weixin-js-sdk'
  import { IsWeiXin } from '../../common/js/isWeiXin'

  export default {
    name: 'UnusedDetail',
    data () {
      return {
//        shopShow: false
        lists: [],
        list: {},
        ordinaryShow: {
          type: Boolean // 普通浏览器
        },
        weixinShow: {
          type: Boolean // 微信浏览器
        }
      }
    },
    mounted () {
      this._getDetail()
      // 图片异步生成，在图片数据更新后调用
      this.$previewRefresh()
      if (IsWeiXin()) {
        this.ordinaryShow = false
        this.weixinShow = true
      } else {
        this.ordinaryShow = true
        this.weixinShow = false
      }
    },
    methods: {
      _getDetail () {
        getDetail(this.$route.params.id).then(res => {
          if (res.code === 200) {
            this.lists = res.data.comment
            this.list = res.data.goods
            // console.log(this.list)
          }
        })
      },
      preview (index) {
        wx.previewImage({
          current: this.list.img[index], // 当前显示图片的http链接
          urls: this.list.img // 需要预览的图片http链接列表
        })
      }
    },
    components: {
      headTop,
      avatar,
      comment
    }
  }
</script>

<style lang="scss">
  @import '../../common/sass/mixin.scss';

  .unused-detail {
    padding-top: 40px;
    background-color: #fff;
    .image {
      width: 100%;
      height: 230px;
      img {
        display: block;
        width: 100%;
        height: 230px;
      }
    }
    .desc,
    .goods {
      padding: 0 10px;
      .desc-wrapper {
        padding: 15px 0;
        .title {
          width: 100%;
          height: 20px;
          font-size: 15px;
          color: rgb(41, 41, 41);
          font-weight: 600;
          margin-bottom: 9px;
          .biaoti {
            width: 66%;
            float: left;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
          }
          .telphone {
            float: right;
            .tel {
              color: #555;
              font-size: 12px;
              vertical-align: middle;
              .phone-image {
                display: inline-block;
                width: 15px;
                height: 15px;
                background-size: 15px 15px;
                background-repeat: no-repeat;
                @include bgimg('./images/dianhua');
                vertical-align: middle;
              }
            }
          }
        }
        .because {
          width: 100%;
          p {
            color: #292929;
            line-height: 18px;
            font-size: 13px;
          }
        }
        .price {
          width: 100%;
          margin-top: 10px;
          padding-bottom: 10px;
          .new-price {
            color: #FD2B33;
            font-size: 15px;
            font-weight: 600;
            float: left;
          }
          .read_num {
            color: #9F9F9F;
            font-size: 14px;
            float: right;
          }
        }
      }
    }
    .split {
      height: 10px;
      background-color: #f1f1f1;
    }
    .good-detail {
      padding: 0 10px;
      .title {
        height: 44px;
        line-height: 44px;
        font-size: 15px;
        font-weight: 600;
        color: #2D2D2D;
      }
      ul {
        width: 100%;
        /*微信浏览器*/
        li {
          width: 100%;
          margin-bottom: 8px;
          background: #f2f2f2;
          height: 200px;
          .imgs {
            width: 100%;
            height: 200px;
            background-size: cover;
            background-position: center;
            border-radius: 10px;
          }
        }
        /*普通浏览器样式*/
        .img_pres {
          width: 100%;
          /*height: 200px;*/
          margin-bottom: 10px;
          .img-box {
            /*float: left;*/
            width: 78%;
            height: 122px;
            border-radius: 10px;
            padding: 11%;
            margin-top: 5px;
            /* margin: 0.65%; */
            position: relative;
            overflow: hidden;
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            img {
              position: absolute;
              width: 100%;
              height: 100%;
              top: 0;
              right: 0;
              bottom: 0;
              left: 0;
              opacity: 0;
            }
          }
        }
      }
    }
  }
</style>
